package com.frogs.ucenter.controller;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.frogs.framework.base.web.BaseController3;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.ucenter.component.UserPermissionHelper;
import com.frogs.ucenter.entity.UserBaseAccountInfo;
import com.frogs.ucenter.service.FeedbackService;

@Controller
public class FeedbackController extends BaseController3 {

	private static Logger log = LoggerFactory.getLogger(FeedbackController.class);
	
	@Resource
	private UserPermissionHelper userPermissionHelper;
	@Resource
	private FeedbackService feedbackService;
	
	@RequestMapping("user/feedback/add")
	public JSONObject addFeedback(HttpServletRequest request, ModelMap model) {
		JSONObject object = new JSONObject();
		try {
    		HttpRequestInfo reqInfo = new HttpRequestInfo(request);
    		String userName = reqInfo.getParameter(ApiUrlParamEnum.username.getParamName(), "-");
    		String phone = reqInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "-");
    		String email = reqInfo.getParameter(ApiUrlParamEnum.email.getParamName(), "-");
    		String content = reqInfo.getParameter(ApiUrlParamEnum.content.getParamName(), "-");
    		String referUrl = reqInfo.getParameter(ApiUrlParamEnum.traceReferUrl.getParamName(), "-");
    		String sex = reqInfo.getParameter(ApiUrlParamEnum.sex.getParamName(), "");
    		
    		
    		UserBaseAccountInfo user = userPermissionHelper.getUser(request);
    		object = feedbackService.addFeedbackInfo(userName, phone, email, content, referUrl, sex, user.getId());
    		return object;
		} catch (Exception e) {
			log.error("func[addFeedback] parameterMap[{}] exception[{} - {}] desc[fail]",//
					new Object[] { request.getParameterMap(), e.getMessage(), Arrays.deepToString(e.getStackTrace()) });
			request.setAttribute("errorMessage", e.getMessage());
			return object;
		}
	}
}
